package cn.lingyangwl.agile.auth.service.impl;

import cn.lingyangwl.agile.auth.service.ThirdClientService;
import cn.lingyangwl.agile.dynamic.client.AbstractClientProcess;
import cn.lingyangwl.agile.dynamic.client.wx.WxMpWrapClient;
import cn.lingyangwl.agile.model.enums.ConfigDefineEnum;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Service;

/**
 * @author shenguangyang
 */
@Slf4j
@Service
public class ThirdClientServiceImpl implements ThirdClientService {

    @Override
    public WxJsapiSignature createWxMpJsapiSignature(String url) {
        WxMpWrapClient dynamicClient = (WxMpWrapClient) AbstractClientProcess.getDynamicClient(ConfigDefineEnum.WX_MP);
        try {
           return dynamicClient.getService().createJsapiSignature(url);
        } catch (WxErrorException e) {
            throw new BizException("获取签名失败-" + e.getError().getErrorMsg());
        }
    }
}
